package client;

public class ClientMain {
	private static final int TICKS_PER_SECOND = 25;
	private static final int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
	private static final int MAX_FRAMESKIP = 5;
	
	/* model class(es) */
	private static ClientModel model;
	private static GraphicView gView;
	private static KeyboardController kbControl;
	private Timer timer;

	public ClientMain() {
		timer = new Timer();
		gameLoop(true);
	}

	private void gameLoop(boolean gameIsRunning) {
		Tick nextGameTick;
		int loops;
		float interpolation;

		while (gameIsRunning) {
			nextGameTick = timer.getTimeElapsedSinceStart();
			/*
			 * getTimeElapsedSinceStart() returns the current number of
			 * milliseconds that have elapsed since the system was started
			 */
			loops = 0;
			while (timer.getTimeElapsedSinceStart().greaterThan(nextGameTick)
					&& loops < MAX_FRAMESKIP) {
				updateGame();

				/* nextGameTick.add(SKIP_TICKS) */;
				loops++;
			}
			interpolation = 0;
			/*
			 * interpolation = float( getTimeElapsedSinceStart() + SKIP_TICKS -
			 * next_game_tick ) / float( SKIP_TICKS );
			 */
			displayGame(interpolation);
		}
	}

	private void updateGame() {
		// TODO calls model.update
	}

	private void displayGame(float interpolation) {
		// TODO Read the game state and render it

	}
}
